package com.tps.cloud.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tps.cloud.system.dto.SystemUserDto;
import com.tps.cloud.system.entity.SystemUser;
import com.tps.cloud.system.mapper.SystemUserMapper;
import com.tps.cloud.system.service.SystemUserService;
import com.tps.cloud.system.vo.SystemUserVo;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * 用户管理 服务实现类
 */
@Service
@AllArgsConstructor
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements SystemUserService {

    @Override
    public Long createUser(SystemUserDto systemUserDto) {
        SystemUser user=new SystemUser();
        BeanUtils.copyProperties(systemUserDto,user);
        this.save(user);
        return user.getId();
    }

    @Override
    public void updateUser(SystemUserDto systemUserDto) {
        SystemUser user=new SystemUser();
        BeanUtils.copyProperties(systemUserDto,user);
        updateById(user);
    }

    @Override
    public SystemUserVo getUser(Long id) {
        SystemUserVo systemUserVo=new SystemUserVo();
        SystemUser systemUser=getById(id);
        BeanUtils.copyProperties(systemUser,systemUserVo);
        return systemUserVo;
    }

    @Override
    public SystemUserVo findByUsername(String username) {
        SystemUserVo systemUserVo=new SystemUserVo();
        SystemUser systemUser= baseMapper.selectOne(SystemUser::getUsername, username);
        BeanUtils.copyProperties(systemUser, systemUserVo);
        return systemUserVo;
    }
}
